<template>
	<view class="Detail">
		<view class="head">
			<view class="head_li">
				<uni-icons type="back" size="30" color="#fff" class="icon_back" @click="navigBack"></uni-icons>
				<text>聊天设置</text>
			</view>
		</view>
		<view>
			<up-modal :show="show" :showCancelButton="true" confirmColor="#000" width="550rpx" @confirm="deleteChat" @cancel="show=false">
				<view class="model" v-show="(model == 'chat')">
					<view class="one">确认后将删除本地聊天记录</view>
					<view class="two">
						<view class="check" v-show="!isChatActive" @click="isChatActive = true"></view>
						<view class="check_active" v-show="isChatActive" @click="isChatActive = false">
							<uni-icons type="checkmarkempty" size="12" color="#fff" class="icon"></uni-icons>
						</view>
						<view>同时删除云端聊天记录</view>
					</view>
				</view>
				<view class="model" v-show="(model == 'friend')">
					<view class="fiend">确定删除该好友吗？删除后好友的聊天记录也会删除</view>
				</view>
			</up-modal>
		</view>
		<scroll-view scroll-y="true" class="body">
			<view class="friend_info">
				<view class="info" @click="Navigator">
					<view class="info_item">
						<image :src="info.avatar"></image>
						<text>{{info.nickname}}</text>
					</view>
					<uni-icons type="forward" size="30" color="#d3d3d3" class="icon"></uni-icons>
				</view>
				<view class="create">
					<view class="circle">
						<uni-icons type="plusempty" size="30" color="#9c9c9c" class="icon"></uni-icons>
					</view>
					<text>发起群聊</text>
				</view>
			</view>
			<view class="chat_set">
				<view class="item" v-for="(item,i) in chatSet" :key="i">
					<text>{{item.name}}</text>
					<up-switch v-model="item.show" size="25" space="5" inactiveColor="#d1d1d1" @click="updataSet(item)"></up-switch>
				</view>
				<view class="tip" style="border: none;">
					<text>消息提醒设置</text>
					<uni-icons type="forward" size="30" color="#d3d3d3" class="icon"></uni-icons>
				</view>
			</view>
			<view class="d_chat" @click="upModel('chat')">
				<text>删除聊天记录</text>
			</view>
			<view class="d_friend" @click="upModel('friend')">
				<text>删除好友</text>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	import {
		mapState,
	} from 'vuex'
	import { getDetail,setTop,setCancelTop,deleteFriend} from '../../common/api';
	import "/common/WebSocket.js";
	export default {
		computed: {
			...mapState('info', ['myInfo'])
		},
		data() {
			return {
				info: {},
				show: false,
				isChatActive:false,
				model:'',
				cId:null,
				chatSet: [{
						name: '设为置顶',
						show: false
					},
					{
						name: '隐藏会话',
						show: false
					},
					{
						name: '消息免打扰',
						show: false
					},
				]
			};
		},
		onLoad(val) {
			this.cId = val.cid;
			this.Init();
		},
		methods: {
			Init(){
				getDetail({
					userId:this.myInfo.id,
					cId:this.cId
				}).then((res)=>{
					if(res){
						this.info = res.data;
						if(this.info.status == '1'){
							this.chatSet[0].show = false;
						}
						if(this.info.status == '3'){
							this.chatSet[0].show = true;
						}
					}
				})
			},
			navigBack() {
				uni.navigateTo({
					url: '/subpkg/chat_interface/chat_interface?cId='+this.cId+'&nickName='+this.info.nickname
				})
			},
			deleteChat(){
				if(this.model == 'chat'){
					if(this.isChatActive){
						this.show = false;
					}
				}
				if(this.model == 'friend'){
					deleteFriend({
						uid:this.myInfo.id,
						fid:this.info.uid,
						cid:this.info.cid
					}).then((res)=>{
						if(res.code == 200){
							uni.showToast({
								title: '删除成功',
								duration: 1000,
								icon:"none"
							});
							uni.switchTab({
								url: '/pages/message/message'
							})
						}
					})
					
				}
			},
			updataSet(item){
				let data = {userId:this.myInfo.id,cId:this.cId}
				if(item.show){
					setTop(data)
				}else{
					setCancelTop(data);
				}
			},
			upModel(val){
				this.show = true;
				this.model = val;
			},
			Navigator(){
				let info = this.info
				uni.navigateTo({
					url: '/subpkg/personal_details/personal_details?fid='+ this.info.uid
				})
			}
		}
	}
</script>

<style lang="scss">
	.Detail {
		.head {
			background: linear-gradient(90deg, rgba(122,220,241,1) 0%, rgba(43,163,242,1) 48%);
			width: 750rpx;
			height: 150rpx;
			position: fixed;

			.head_li {
				position: absolute;
				bottom: 0;
				width: 750rpx;
				height: 120rpx;
				display: flex;
				line-height: 100rpx;
				padding: 0rpx 0rpx;

				text {
					color: #fff;
					font-size: 33rpx;
					opacity: 0.8;
					padding: 15rpx 210rpx;
					display: flex;
					line-height: 80rpx;
				}

				.icon_back {
					padding: 15rpx 20rpx;
				}
			}
		}
		.model{
			.one{
				font-size: 28rpx;
			}
			.two{
				height: 40rpx;
				display: flex;
				font-size: 24rpx;
				color: #a6a6a6;
				align-items: center;
				justify-content: center;
				padding-top: 20rpx;
				.check{
					width: 30rpx;
					height: 30rpx;
					border: 1rpx solid #a6a6a6;
					border-radius: 30rpx;
					margin-top: 5rpx;
					margin-right: 10rpx;
				}
				.check_active{
					width: 30rpx;
					height: 30rpx;
					border-radius: 30rpx;
					margin-top: 5rpx;
					margin-right: 10rpx;
					background-color: #1caaf5;
					display: flex;
					justify-content: center;
					align-items: center;
				}
			}
			.fiend{
				height: 40rpx;
				display: flex;
				font-size: 30rpx;
				align-items: center;
				justify-content: center;
				padding: 20rpx 0;
			}
		}
		.body {
			position: fixed;
			top: 150rpx;
			height: 90vh;
			background-color: #e9e9e9;

			%base {
				background-color: rgba(250, 250, 250, 0.8);
				backdrop-filter: blur(10rpx);
				border-radius: 20rpx;
				margin: 20rpx;
				padding: 20rpx;
			}

			.friend_info {
				@extend %base;
				padding: 20rpx 30rpx;

				.info {
					display: flex;
					justify-content: space-between;
					align-items: center;
					border-bottom: 1rpx solid rgba(200, 200, 200, 0.5);

					.info_item {
						min-width: 200rpx;
						display: flex;
						justify-content: space-around;
						align-items: center;
						padding-bottom: 25rpx;

						image {
							width: 100rpx;
							height: 100rpx;
							border-radius: 50rpx;
						}

						text {
							font-size: 32rpx;
							padding-left: 20rpx;
						}
					}

					.icon {
						padding: 0 20rpx;
					}
				}

				.create {
					display: flex;
					align-items: center;
					padding-top: 25rpx;

					.circle {
						width: 100rpx;
						height: 100rpx;
						border-radius: 50rpx;
						background-color: #d6d6d6;
						display: flex;
						justify-content: center;
						align-items: center;
						margin: 10rpx 0;

					}

					text {
						font-size: 32rpx;
						padding: 0 20rpx;
					}
				}
			}

			.chat_set {
				@extend %base;
				padding-top: 10rpx;

				.item {
					display: flex;
					justify-content: space-between;
					align-items: center;
					padding: 20rpx;
					padding-bottom: 30rpx;
					font-size: 32rpx;
					border-bottom: 1rpx solid rgba(200, 200, 200, 0.5);
				}
			}

			.tip {
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin: 0 -30rpx -30rpx -30rpx;
				padding: 20rpx 50rpx;
				padding-bottom: 30rpx;
				font-size: 30rpx;
				border-radius: 0 0 20rpx 20rpx;

				&:active {
					background-color: #d6d6d6;
					transition: background-color 0.1s;
				}
			}

			.d_chat {
				@extend %base;
				font-size: 32rpx;
				padding: 30rpx 40rpx;

				&:active {
					background-color: #d6d6d6;
					transition: background-color 0.1s;
				}
			}

			.d_friend {
				@extend %base;
				font-size: 32rpx;
				color: #d63215;
				display: flex;
				justify-content: center;
				padding: 30rpx 0;

				&:active {
					background-color: #d6d6d6;
					transition: background-color 0.1s;
				}
			}
		}
	}
</style>